@extends("layouts.backend.webadmin")
@section('page-header')
<h1>
    <small>project manage index</small>
</h1>
@endsection

@section('content')
<link rel="stylesheet" href="{{env('APP_ROOT')}}/assets/select2/css/select2.min.css">
<link rel="stylesheet" href="{{env('APP_ROOT')}}/css/protasklist.css">
<!-- Main content -->
<section class="content">
    <div class="row">
        <div class="col-xs-12">

            <div class="box">
                <div class="box-header">
                    <a class="btn btn-primary projectmanage-add" href="{{route('admin.projectmanage.addpage')}}" role="button"><i class="fa fa-plus-square" aria-hidden="true"></i> 提交</a>
                    <a class="btn btn-info" href="javascript:;" role="button" data-widget="collapse"><i class="fa fa-bars"></i> 搜索</a>
                </div>
                <form id="filterForm" class="form-inline" role="form" action="{{ URL::route('admin.projectmanage.search') }}" method="post">
                    <div class="box-body">
                        <div>
                            <div class="form-group date">
                                <label for="startTime col-sm-2">时间:</label>
                                <div class="input-group col-sm-10">
                                    <input type="text" class="form-control pull-left time" placeholder="开始时间" name="startTime" value="">
                                    <div class="input-group-addon">
                                        <i class="fa fa-calendar"></i>
                                    </div>
                                    <input type="text" class="form-control pull-left time" placeholder="结束时间" name="endTime" value="">
                                    <div class="input-group-addon">
                                        <i class="fa fa-calendar"></i>
                                    </div>
                                </div>
                            </div>
                            <div class="form-group">
                                <label for="pcp">责任人:</label>
                                <div class="form-group">
                                    <select class="form-control select2" aria-hidden="true" name="pcp">
                                        <option value=""> 所有</option>
                                        @foreach($pcp as $pc)
                                            <option @if(old('pcp')==$pc->id) selected @endif value="{{$pc->id}}">{{$pc->name}}</option>
                                        @endforeach
                                    </select>
                                </div>
                            </div>
                            <div class="form-group">
                                <label for="searchStatus">状态:</label>
                                <div class="form-group  ">
                                    <select class="form-control" name="status">
                                        <option value="">所有</option>
                                        <option value="1">计划中</option>
                                        <option value="2">进行中</option>
                                        <option value="3">已完成</option>
                                        <option value="4">已删除</option>
                                    </select>
                                </div>
                            </div>
                            <div class=" form-group">
                                <label for="searchApp">应用名称</label>
                                <div class="form-group">
                                    <select class="form-control select2" name="app">
                                        <option value="">所有</option>
                                        @foreach($apps as $app)
                                            <option @if(old('app_id')==$app->id || $app->id==$appId) selected @endif value="{{$app->id}}">{{$app->name}}</option>
                                        @endforeach
                                    </select>
                                </div>
                            </div>
                            <div class="form-group">
                                <label for="searchKeywords">关键字</label>
                                <div class="form-group">
                                    <input type="text" class="form-control" placeholder="项目名称" name="keywords">
                                </div>
                            </div>
                            <div class="form-group">
                                <label for="searchbtn"> </label>
                                <button type="button" class="btn btn-primary" name="searchbtn"><i class="fa fa-search"></i>搜索</button>
                                <a  href="{{route('admin.projectmanage.export')}}" type="button" class=" btn btn-success projectmanage-export" name="importbtn"><i class="fa fa-download"></i>导出</a>
                            </div>
                        </div>
                    </div>
                </form>
                <div class="box-body1">
                    <table id="pm-list" class="table table-bordered table-striped">
                        <thead>
                        <tr>

                        </tr>
                        </thead>

                        <tbody>
                        </tbody>
                    </table>

                </div>
            </div>
        </div>
    </div>
</section>
@stop
@section('javascript-end')
<script src="{{env('APP_ROOT')}}/js/common.js"></script>
<script src="{{env('APP_ROOT')}}/assets/select2/js/select2.min.js"></script>
<script>
    $(function () {
        console.log('welcome to pm page.');
        var m1 = manage();
        var tables = $('#pm-list').DataTable({
            //调整结构
            "dom": '<"dataTables_filter">rtip',
            "autoWidth":true,
            //国际化
            'oLanguage'   :{
                'sUrl'    : '{{env("APP_ROOT")}}/assets/bootstrap/js/zh_cn.json'
            },
            "paging": true, // 禁止分页
            "bSort": false,//禁止排序
            "processing": true,
            //开启服务器模式
            serverSide: true,
            ajax: {
                //指定数据源
                url: "{{route('admin.projectmanage.search')}}",
                type: "GET",
                data: function(d){
                    delete d.columns;
                    return d;
                },
                //接受服务器数据
                dataSrc:function(json){
                    getToken();
                    return json.data;
                }
            },
            pageLength: {{  $pageNum }},
            //data值对应数据库字段名
            columns: [
                {
                    'title':'编号',
                    "data": "pro_number"
                },
                {
                    'title':'项目名称',
                    "data": "name"
                },
                {
                    'title':'目标应用',
                    'data':"app"
                },
                {
                    'title':'责任人',
                    'data':'pcp'
                },
                {
                    'title':'状态',
                    'data':'statusStr',
                    "render": function(data,type,row,meta){
                        if (row.status==2) {
                            return '<span style="color: red;">进行中</span>';
                        }else{
                            return data;
                        }
                    }
                },
                {
                    'title':'开始时间',
                    'data':'started_at'
                },
                {
                    'title':'结束时间',
                    'data':'ended_at'
                },
                {
                    'title':'漏洞数',
                    'data':'vul_num'
                },
                {
                    "title":"操作",
                    "targets": -2,
                    "data": null,
                    "render": function(data,type,row,meta){
                        var url = "{{route('admin.projectmanage.detail')}}"+'?id='+row['id'];
                        var strBtn = '<a href="'+url+'" class="btn btn-primary projectmanage-detail" type="button">查看</a>';
                        strBtn += '&nbsp;<a href="{{route('admin.checkoption.index')}}?tid='+row['id']+'" class="btn btn-primary checkoption-index" type="button">测试项</a>';
                        return strBtn;
                    }
                }],
            //所有列过滤xss
            columnDefs: [{
                "targets": "_all",
                "render": $.fn.dataTable.render.text()
            }]
        });
        //日历插件
        $('.time').datepicker({
            autoclose: true
        });
        //下拉筛选
        $('.select2').select2({"border-radius":'0px'});
        //筛选条件
        $(':input[name="searchbtn"]').click(function () {

            var formData =$('#filterForm').serialize();

            tables.search( formData ).draw();
        });
        //app外链进入
        var app = "{{$appId}}";
        if(app){
            tables.search('app='+app).draw();
        }
    });
</script>
@endsection
